import unittest
from collections import OrderedDict

from network_data import *
from layout_algorithm import *

class TestNetworkData(unittest.TestCase):
    def setUp(self):
        n = NetworkData()

    def test_container(self):
        n = NetworkData()
        self.assertTrue(n.getCurrentPos() == 0)
        self.assertTrue(n.current() is not None)
        network = n.current()
        self.assertTrue(network["edges"] is not None)
        self.assertTrue(network["nodes"] is not None)
        self.assertTrue(len(n) == 1)
        m = NetworkData()
        self.assertTrue(len(m) == 1)

    def test_next_prev(self):
        x = NetworkData()
        self.assertTrue(len(x) == 1)
        network1 = x.current()
        self.assertTrue(x.current() is not None)
        layout = LayoutAlgorithmIGraph()
        layout.execute(x.current())

        x.next()
        self.assertTrue(len(x) == 2)
        self.assertTrue(x.getCurrentPos() == 1)
        network2 = x.current()
        self.assertTrue(x.current() is not None)
        self.assertTrue(network1 is not network2)

        x.prev()
        self.assertTrue(len(x) == 2)
        self.assertTrue(x.getCurrentPos() == 0)
        network3 = x.current()
        self.assertTrue(x.current() is not None)
        self.assertTrue(network1 == network3)

    def test_odict(self):
        d = OrderedDict([("red", (255, 0, 0)), ("orange", (255, 108, 0)),
                         ("yellow", (204, 255, 0)), ("green", (0, 255, 90)),
                         ("blue", (36, 182, 218)), ("indigo", (0, 18, 255)),
                         ("purple", (216, 0, 255)), ("gray", (188, 188, 188))])
        l1 = list(d.keys())
        self.assertTrue(l1 == ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'purple', 'gray'])


class TestVadData(unittest.TestCase):
    def setUp(self):
        v = VadData("408", 0)
    
    def test_container(self):
        v = VadData("408", 0)
        self.assertTrue(v.getCurrentPos() == 0)
        self.assertTrue(v.current() is not None)
        vadtree = v.current()
        self.assertTrue(vadtree["edges"] is not None)
        self.assertTrue(vadtree["nodes"] is not None)
        self.assertTrue(len(v) == 1)
        w = VadData("976", 0)
        self.assertTrue(len(w) == 1)

    def test_current(self):
        y = VadData("408", 1)
        self.assertTrue(len(y) == 1)
        y._pid = "408"
        y._vadtree_pos = 1
        vadtree1 = y.current()
        self.assertTrue(len(y) == 2)
        self.assertTrue(y.getCurrentPos() == 1)
        z = VadData("976", 0)
        z._pid = "976"
        z._vadtree_pos = 0
        self.assertTrue(len(z) == 2)
        self.assertTrue(z.getCurrentPos() == 0)


if __name__ == '__main__':
    unittest.main()
